class Solution
{
public:
    long long maximumSum(vector<int> &nums)
    {
        int n = nums.size(); // 1e4
        vector<int> completeIndexSubset;
        int sqrtN = int(sqrt(n) + 0.5);
        for (int i = 1; i <= sqrtN; ++i)
        {
            completeIndexSubset.push_back(i * i);
        } // 1e2
        long long result = 0;
        for (int k = 1; k <= n; ++k)
        {
            long long subsetSum = 0;
            for (int index : completeIndexSubset)
            {
                index *= k;
                if (index > n)
                {
                    break;
                }
                subsetSum += nums[index - 1];
            }
            result = max(result, subsetSum);
        }
        return result;
    }
};